package com.kun.config.interceptor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;

@Configuration
public class MyJwtInterceptor implements WebMvcConfigurer {


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        ArrayList<String> list = new ArrayList<>();
        list.add("/index/user/login");
        list.add("/swagger-resources/**");
        list.add("/swagger-ui.html/**");
        registry.addInterceptor(jwtInterceptor())
                .addPathPatterns("/**")     //所有请求都要经过jwt认证
                .excludePathPatterns(list);   //以下请求除外
    }

    @Bean
    public DiyJwtInterceptor jwtInterceptor(){
        return new DiyJwtInterceptor();
    }


}
